// This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
class procedure FindLocalApplications.Main;
const
UAApplicationTypes_Server = 1;
var
Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
Count: Cardinal;
Element: OleVariant;
DiscoveryElement: _UADiscoveryElement;
DiscoveryElementEnumerator: IEnumVariant;
DiscoveryElements: _UADiscoveryElementCollection;
DiscoveryUriStrings: OleVariant;
begin
DiscoveryUriStrings := VarArrayCreate([0, 2], varVariant);
DiscoveryUriStrings[0] := 'opc.tcp://opcua.demo-this.com:4840/UADiscovery';
DiscoveryUriStrings[1] := 'http://opcua.demo-this.com/UADiscovery/Default.svc';
DiscoveryUriStrings[2] := 'http://opcua.demo-this.com:52601/UADiscovery';
// Instantiate the client object
Client := CoEasyUAClient.Create;
// Obtain collection of application elements
try
DiscoveryElements := Client.FindLocalApplications(DiscoveryUriStrings, UAApplicationTypes_Server);
except
on E: EOleException do
begin
WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
Exit;
end;
end;
// Display results
DiscoveryElementEnumerator := DiscoveryElements.GetEnumerator;
while (DiscoveryElementEnumerator.Next(1, Element, Count) = S_OK) do
begin
DiscoveryElement := IUnknown(Element) as _UADiscoveryElement;
WriteLn(
'DiscoveryElements["',
DiscoveryElement.DiscoveryUriString,
'".ApplicationUriString: ',
DiscoveryElement.ApplicationUriString);
end;
VarClear(DiscoveryUriStrings);
end;
Rem This example shows how to obtain application URLs of all OPC Unified Architecture servers, using specified discovery URI strings.
Public Sub FindLocalApplications_Main_Command_Click()
OutputText = ""
Dim DiscoveryUriStrings(2)
DiscoveryUriStrings(0) = "opc.tcp://opcua.demo-this.com:4840/UADiscovery"
DiscoveryUriStrings(1) = "http://opcua.demo-this.com/UADiscovery/Default.svc"
DiscoveryUriStrings(2) = "http://opcua.demo-this.com:52601/UADiscovery"
' Instantiate the client object
Dim Client As New EasyUAClient
' Obtain collection of application elements
On Error Resume Next
Dim DiscoveryElementCollection As UADiscoveryElementCollection
Set DiscoveryElementCollection = Client.FindLocalApplications(DiscoveryUriStrings, UAApplicationTypes_Server)
If Err.Number <> 0 Then
OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
Exit Sub
End If
On Error GoTo 0
' Display results
Dim DiscoveryElement As UADiscoveryElement: For Each DiscoveryElement In DiscoveryElementCollection
OutputText = OutputText & "DiscoveryElementCollection[""" & DiscoveryElement.DiscoveryUriString & """].ApplicationUriString: " & _
DiscoveryElement.applicationUriString & vbCrLf
Next
End Sub